import 'dart:convert';

import 'package:bruno/bruno.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_driver/AppConfig/LocalStorage.dart';
import 'package:sph_driver/Main/FleetManagement/MyFleet.dart';

import '../../AppConfig/Config.dart';
import '../../AppConfig/RouteAct.dart';
import '../../http/NoLoadingPostApi.dart';
import '../../http/api.dart';
import '../../l10n/messages.dart';

class FleetManagement extends StatefulWidget {
  const FleetManagement({super.key, required this.userMap});
  final Map userMap;
  @override
  State<FleetManagement> createState() => _FleetManagementState();
}

class _FleetManagementState extends State<FleetManagement> {
  List titleList=["1.队员上报需求","2.车队分单","3.车辆定位","4.车队长代收运费","5.站内沟通","6.订单查询","7.回单上传"];
  List textList=["根据队员上报找货需求，系统智能推送货源至车队长。",
    "车队长接单后可在线分配运单给车队司机，货主和司机同步接受信息，提升管理效率。",
    "货主和车队长可随时查看在途车辆位置，让货主更放心。",
    "支持运费 (司机同意后) 代收至车队长账户，避免多层转费，资金快速回笼。",
    "支持车队长与车队成员一对一、一对多群发通知增加沟通效率。",
    "车队运单统一管理，后续查找无烦恼。",
    "回单车队长，司机，货主轻松同步查。"];
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text(messages['车队管理'],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
      ),
      body: Column(
        children: [
      Expanded(child:
      Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,  // 从上开始
            end: Alignment.bottomCenter,  // 到下结束
            colors: [Color(0xFFFBECE4), Colors.white],  // 渐变色数组
          ),
        ),
        child:
        ListView(
          children: [
            Container(
              margin: EdgeInsets.only(top: 8.h,right: 10.w,left: 10.w),
              padding: EdgeInsets.only(left: 20.w,right: 15.w,top: 15.h,bottom: 15.h),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Text("车队管理是一套简易的免费为车队提供方便的管理工具，支持成员一键上报找货需求，车队长在线接单分单，查看在途订单定位，车队长运费代收，违章查询，运单查询，站内沟通等。"
                ,style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300),),
            ),
            Container(
              height:textList.length *68.h,
              margin: EdgeInsets.only(top: 8.h,right: 10.w,left: 10.w),
              padding: EdgeInsets.only(left: 20.w,right: 15.w,top: 15.h,bottom: 15.h),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: ListView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  itemCount: textList.length,
                  itemBuilder: (BuildContext context, int index) {
                    return Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(titleList[index],style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp,fontWeight: FontWeight.w600),),
                        SizedBox(height: 8.h,),
                        Text(textList[index],style: TextStyle(color: Colors.black),),
                        SizedBox(height: 8.h,),
                      ],
                    );
                  }
              ),
            )
          ],
        ),
      ),
      ),
          Container(
            height: 80.h,
            color: Colors.white,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                    height: 40.h ,
                    margin: EdgeInsets.only(left: 30.w,right: 30.w),
                    decoration: BoxDecoration(
                        color:Color.fromRGBO(231, 112, 27, 0.85),
                        borderRadius: BorderRadius.all(Radius.circular(30))),

                    width: double.infinity,


                    child: TextButton(
                      child: Text(messages["成为车队长"],style: TextStyle(color: Colors.white,fontSize: 14.sp,fontWeight: FontWeight.w600),),

                      onPressed: () async {

                        String?drvId =await UserIdManager.getUserID();

                        NoLoadingApiManager.postData(
                          context,
                          'api/auth/driver/fleet/add',
                          {
                            "driverId":drvId,
                            "avatarPath":"sph56/driver/1781255212293775361/avatar/1781255212293775361_avatar.png",
                            "name":"仔仔的车队",
                            // "avatarPath":widget.userMap['avatarPath'],
                            // "name":widget.userMap['realName']+"的车队",
                          },
                              (responseData) {
                            setState(() {
                              BrnToast.show(
                                "添加成功",
                                context,
                                duration: BrnDuration.short,
                              );
                           Navigator.push( context, FadeRoute(page:MyFleet(captainId: drvId!,)));
                             // Navigator.pop(context,"success");
                            });
                          },
                        );

                          // Navigator.push( context, FadeRoute(page:MyFleet()));
                      },
                    )
                ),
              ],
            ),
          ),
      ]
      ),

    );
  }
}
